
// <copyright file="DictionaryEnumerable.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The dictionary enumerable.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System.Collections;
    using System.Collections.Generic;

    /// <summary>
    /// The dictionary enumerable.
    /// </summary>
    /// <typeparam name="TKey">
    /// The type of the key.
    /// </typeparam>
    /// <typeparam name="TValue">
    /// The type of the value.
    /// </typeparam>
    public class DictionaryEnumerable<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
    {
        #region Fields

        /// <summary>
        /// The callback.
        /// </summary>
        private readonly EnterOrExitReadLock _callback;

        /// <summary>
        /// The dictionary.
        /// </summary>
        private readonly IDictionary<TKey, TValue> _dictionary;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryEnumerable{TKey,TValue}"/> class.
        /// </summary>
        /// <param name="dictionary">
        /// The dictionary.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        public DictionaryEnumerable(IDictionary<TKey, TValue> dictionary, EnterOrExitReadLock callback)
        {
            this._dictionary = dictionary;
            this._callback = callback;
        }

        #endregion Constructors and Finalizers

        #region Public Methods and Operators

        /// <summary>
        /// The get enumerator.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerator"/>.
        /// </returns>
        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            return new DictionaryEnumerator<TKey, TValue>(this._dictionary, this._callback);
        }

        #endregion Public Methods and Operators

        #region Explicit Interface Methods

        /// <summary>
        /// The get enumerator.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerator"/>.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return new DictionaryEnumerator<TKey, TValue>(this._dictionary, this._callback);
        }

        #endregion Explicit Interface Methods
    }
}